//
//  WYHomeBrandCell.m
//  Hangbag
//
//  Created by admin on 2018/2/9.
//  Copyright © 2018年 admin. All rights reserved.
//

#import "WYHomeBrandCell.h"
#import "WYBrandCollectionViewCell.h"
#import "WYBagModel.h"
@interface WYHomeBrandCell()<UICollectionViewDelegate,UICollectionViewDataSource>

@property (strong, nonatomic) IBOutlet UICollectionView *collectionview;

@end


@implementation WYHomeBrandCell
-(void)setDataArray:(NSMutableArray *)dataArray
{
    _dataArray=dataArray;
    [self.collectionview reloadData];
}
- (void)awakeFromNib {
    [super awakeFromNib];
    
    [self setupUI];
    
}
-(void)setupUI
{
    self.collectionview.delegate=self;
    self.collectionview.dataSource=self;
    
    self.collectionview.bounces=NO;
    UICollectionViewFlowLayout *layout=[[UICollectionViewFlowLayout alloc]init];
    layout.itemSize=CGSizeMake(100, 20);
    //横向最小距离
    layout.minimumInteritemSpacing=1.0f;
    layout.minimumLineSpacing=1.0f;
    //cell距离上  左  下 右 的距离
    layout.sectionInset=UIEdgeInsetsMake(0,6, 0, 6);
    [layout setScrollDirection:UICollectionViewScrollDirectionVertical];
    [layout setHeaderReferenceSize:CGSizeMake(kScreenWidth, 50)];
    [self.collectionview setCollectionViewLayout:layout];
    [self.collectionview registerNib:[UINib nibWithNibName:@"WYBrandCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"WYBrandCollectionViewCell"];
    self.collectionview.showsHorizontalScrollIndicator = NO;
    
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
}

-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.dataArray.count;
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    WYBrandCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"WYBrandCollectionViewCell" forIndexPath:indexPath];
    WYBagModel *model  = self.dataArray[indexPath.row];
    
    [cell.brandImageView sd_setImageWithURL:[NSURL URLWithString:model.img] placeholderImage:nil];
        return cell;
}
#pragma mark- collectionViewDatasource
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
    return 1.0f;
}
-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
{
    return 1.0f;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    CGFloat itemWith =(kScreenWidth-48)/3;
    
    return CGSizeMake(itemWith, itemWith/1.4);
}







@end
